package com.ce.pms.report.service;

import java.util.ArrayList;
import java.util.List;

import com.ce.pms.charge.dao.IChargeVoucherDao;
import com.ce.pms.charge.service.IChargeVoucherService;
import com.ce.pms.report.queryvo.ChargeVoucherReportQueryVO;
import com.ce.pms.report.vo.ChargeVoucherReportVO;
import com.ce.pms.report.vo.ChargeVoucherSubVO;
import com.ce.pms.report.vo.PrintChargeNoteSubVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;

/**
 *
 * 功能描述：
 * <p>
 * 版权所有：中企动力
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 黄彦军 Created on 2008-9-5 Edit author: Edit on: 修改原因:
 */

public class ChargeVoucherReportService  implements ICEReportDataSetService{

	private IChargeVoucherService chargeVoucherService;
	private IChargeVoucherDao chargeVoucherDao;

	public IChargeVoucherDao getChargeVoucherDao() {
		return chargeVoucherDao;
	}

	public void setChargeVoucherDao(IChargeVoucherDao chargeVoucherDao) {
		this.chargeVoucherDao = chargeVoucherDao;
	}

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg) throws CEReportException {
		ChargeVoucherReportQueryVO queryVO = (ChargeVoucherReportQueryVO) arg;
		//chargeVoucherDao.updateVoucherStart(queryVO.getVoucherId());
		List list =this.getReportInfo(queryVO.getVoucherId(), queryVO.getHouseId());

		return new CEReportDataSet(list);
	}

	/**
	 * 功能描述:获取打印信息  <br>
	 * @param voucherId
	 * @param houseId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-10-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<ChargeVoucherReportVO> getReportInfo(Long voucherId,Long houseId){
		ChargeVoucherReportVO reportVO = chargeVoucherService.voucherReport(voucherId, houseId);
		List<ChargeVoucherSubVO> subList = reportVO.getSubList();
		if (!BlankUtil.isBlank(subList)){
			int count = subList.size();
			if(count > 13){ //如果子报表数据大于13条，则删除多于13条的数据
				for(int i = count - 13;i > 0; i--){
					subList.remove(i + 12);
				}
			}else if(count < 13){ //如果子报表数据小于13条，则添加至13条数据
				for(int i = 13 - count; i > 0; i--){
					subList.add(new ChargeVoucherSubVO());
				}
			}

		}else{
			for (int i = 0; i < 13; i++) {
				subList.add(new ChargeVoucherSubVO());
			}
		}

		List<ChargeVoucherReportVO>  list = new ArrayList<ChargeVoucherReportVO>();
		list.add(reportVO);
		return list;
	}


	public IChargeVoucherService getChargeVoucherService() {
		return chargeVoucherService;
	}

	public void setChargeVoucherService(IChargeVoucherService chargeVoucherService) {
		this.chargeVoucherService = chargeVoucherService;
	}



}
